﻿(function ($) {

    $.fn.tabs = function (options, param) {

            if (typeof options == 'string') {
            switch(options) {
                case 'add':
                    return addTab(param);
                case 'close':
                    return closeTab(param);
                case 'subclose':
                    return subcloseTab(param);
                case 'select':
                    return selectTab(param);
                case 'exists':
                    return exists(param);
                case 'selected':
                    return selected();
                default:
                    return;
            }
        }
        function addTab(id, title, url, closable, selected, callback) {
            var self = this;
            if (!id) return;
            closable = (typeof (closable) == 'undefined') ? true : closable;
            selected = (typeof (selected) == 'undefined') ? true : selected;
            //var height = self.isTouchDevice() ? 'auto' : '100%';
            var height = '100%';
            jQuery('#tabs_container').tabs('add', {
                id: id,
                title: title,
                closable: closable,
                selected: selected,
                style: 'height:' + height + ';',
                content: '<iframe id="tabs_' + id + '_iframe" name="tabs_' + id + '_iframe" allowTransparency= "true"' + (!selected ? (' _src="' + url + '"') : '') + ' src="' + (selected ? url : '') + '"' + (selected ? (' onload="IframeLoaded(\'' + id + '\');"') : '') + ' border="0" frameborder="0" framespacing="0" marginheight="0" marginwidth="0" style="width:100%;height:' + height + ';"></iframe>',
                callback: function () {
                    pulser.pulseFormer();
                    callback && callback();
                }
            });
        }
        function closeTab(id){
            $('#tabs_container').tabs('close', id);
        }
    };
})(jQuery);